<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseWards {

	protected $m_intId;
	protected $m_intRoomNumber;
	protected $m_intWardTypeId;
	protected $m_intRate;
	protected $m_intIsAvaliable;
	protected $m_strMoveOutDate;
	protected $m_intReservationId;
	protected $m_intReportingDoctorId;
	protected $m_intPatientId;
	protected $m_intDepartmentId;
	protected $m_strFacilities;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_strUpdatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getRoomNumber(){
		return $this->m_intRoomNumber;
	}

	public function getWardTypeId(){
		return $this->m_intWardTypeId;
	}

	public function getRate(){
		return $this->m_intRate;
	}

	public function getIsAvaliable(){
		return $this->m_intIsAvaliable;
	}

	public function getMoveOutDate(){
		return $this->m_strMoveOutDate;
	}

	public function getReservationId(){
		return $this->m_intReservationId;
	}

	public function getReportingDoctorId(){
		return $this->m_intReportingDoctorId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getDepartmentId(){
		return $this->m_intDepartmentId;
	}

	public function getFacilities(){
		return $this->m_strFacilities;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_strUpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setRoomNumber( $RoomNumber ){
		$this->m_intRoomNumber = $RoomNumber;
	}

	public function setWardTypeId( $WardTypeId ){
		$this->m_intWardTypeId = $WardTypeId;
	}

	public function setRate( $Rate ){
		$this->m_intRate = $Rate;
	}

	public function setIsAvaliable( $IsAvaliable ){
		$this->m_intIsAvaliable = $IsAvaliable;
	}

	public function setMoveOutDate( $MoveOutDate ){
		$this->m_strMoveOutDate = $MoveOutDate;
	}

	public function setReservationId( $ReservationId ){
		$this->m_intReservationId = $ReservationId;
	}

	public function setReportingDoctorId( $ReportingDoctorId ){
		$this->m_intReportingDoctorId = $ReportingDoctorId;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setDepartmentId( $DepartmentId ){
		$this->m_intDepartmentId = $DepartmentId;
	}

	public function setFacilities( $Facilities ){
		$this->m_strFacilities = $Facilities;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_strUpdatedOn = $UpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into WARDS (room_number, ward_type_id, rate, is_avaliable, move_out_date, reservation_id, reporting_doctor_id, patient_id, department_id, facilities, created_by, created_on, updated_by, updated_on) values (" . $this->getRoomNumber() . ", " . $this->getWardTypeId() . ", " . $this->getRate() . ", " . $this->getIsAvaliable() . ", '" . $this->getMoveOutDate() . "', " . $this->getReservationId() . ", " . $this->getReportingDoctorId() . ", " . $this->getPatientId() . ", " . $this->getDepartmentId() . ", '" . $this->getFacilities() . "', " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE WARDS set  room_number= " . $this->getRoomNumber() . ", ward_type_id= " . $this->getWardTypeId() . ", rate= " . $this->getRate() . ", is_avaliable= " . $this->getIsAvaliable() . ", move_out_date= '" . $this->getMoveOutDate() . "', reservation_id= " . $this->getReservationId() . ", reporting_doctor_id= " . $this->getReportingDoctorId() . ", patient_id= " . $this->getPatientId() . ", department_id= " . $this->getDepartmentId() . ", facilities= '" . $this->getFacilities() . "', created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now()  where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM wards WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'wards'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}